<template>
	<view class="page">
		<view class="top">

			<view class="info u-flex u-row-between">
				<view class="u-flex">
					<u-image :src="info.avatar" width="130" height="130" shape="circle"></u-image>
					<view class="u-margin-left-20">
						<view class="" v-if="info.nickname">
							<view style="color: #FFFFFF;font-size: 34rpx;">{{info.nickname}}</view>
						</view>
						<view v-else style="font-size: 34rpx;color: #fff;">
							<navigator url="../register/index" hover-class="none">
								点击登陆
							</navigator>
						</view>
					</view>
					
				</view> 
				<!-- <view class="" >
			         <u-button @click="changeLocation"  size="mini" type="warning">修改地址</u-button>
				</view> -->
			</view>


			<view class="nav " >
				<view>去推广</view>
				<view style="position: relative;" @click="drawImage">
					邀请下级
					<u-icon name="arrow-right" color="#FFE87F"></u-icon>
					<!-- <button open-type="share" class="custom-btn">555</button> -->
				</view>
			</view>
		</view>

		<view class="mode u-margin-top-40" style="padding: 10rpx;">
			<u-cell-group :border="false">
				<u-cell-item title="我的关注" @click="go('/pages/care/index')">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/care.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
			<!-- 	<u-cell-item title="我的评价" @click="go('/pages/evaluate/my')">
					<view slot="icon" class="u-margin-right-20 u-margin-top-20">
						<u-icon name="/static/evaluate.png" size="38"></u-icon>
					</view>
				</u-cell-item> -->
				<u-cell-item title="分销中心"  @click="go('/pages/fenxiao/index')"  v-if="!site">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/fenxiao.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
				<u-cell-item title="我的优惠券" :border-bottom="false" @click="go('/pages/coupon/index')">
					<view slot="icon" class="u-margin-right-20 u-margin-top-10">
						<u-image src="/static/coupond.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		
		
		<view class="mode u-margin-top-40" style="padding: 10rpx;">
			<u-cell-group :border="false">
				<u-cell-item :title="info.is_auth==2? '技师中心':'技师申请' " @click="apply">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/apply.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
				<u-cell-item title="代理申请"  @click="agent">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/agent.png" width="38" height="38" mode="widthFix"></u-image>
					</view>
				</u-cell-item>  
				<u-cell-item title="关于平台"  @click="go('/pages/about/index')">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/about.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
				<u-cell-item title="意见反馈" :border-bottom="false" @click="go('/pages/adv/index')">
					<view slot="icon" class="u-margin-right-20 ">
						<u-image src="/static/adv.png" width="38" height="38" mode="widthFix"></u-image>
						
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		
		<canvas id="qrcode" canvas-id="qrcode" style="width: 354px;height: 354px;position: fixed;left: -1000%;top: -1000%;" />
		
		
		
		<r-canvas ref="rCanvas" @click="save" :image="image"></r-canvas>
		
		
		
		<!-- <u-mask :show="show" @click="close" :customStyle="{paddingTop:'100rpx'}" >
			
		   <r-canvas ref="rCanvas" @click="save" :image="image"></r-canvas>
		   <u-button :custom-style="{width:'80%',marginTop:'20rpx'}" type="success" @click="save" shape="circle">保存图片</u-button>
				
		</u-mask> -->
	</view>
</template>

<script>
	import rCanvas from "@/components/r-canvas/r-canvas.vue";
	import uQRCode from './uqrcode.js';
		import draw from './post.js';
		import baseUrl from "@/common/baseUrl.js";
	export default {
		components: {
			rCanvas
		},
		data() {
			return {
				show:false,
				info: {
					avatar: "/static/logo.png",
					nickname: "",
					
				},
				poster:'',
				image:"",
				site:''
			}
		},
		onShow() {
			
			this.jiazai();
			this.getSite()
		},
		
	

	
		
		methods:{
			changeLocation(){
				uni.navigateTo({
					url:'./changeLocation'
				})
			},
			
			
			getSite(){
				this.$u.post('/index/siteStatus', {
				}).then(res => {
					this.site=res.switch;
				}).catch(err => {})
			},
		    
			getQr(){
				uni.showLoading({
					title:"正在努力绘制中...",
				})
				 return new Promise((resolve,reject)=>{
					 uQRCode.make({
						canvasId: 'qrcode',
						componentInstance: this,
						size: 354,
						margin: 10,
						text: baseUrl.net+`?pid=${this.info.id}`,
						backgroundColor: '#ffffff',
						foregroundColor: '#000',
						fileType: 'png',
						errorCorrectLevel: uQRCode.errorCorrectLevel.H
					})
					.then(res => {
						resolve(res.tempFilePath)
					})
				 })
			},
			
			async drawImage() {
				let res = await this.getPost();
			    let qr = await this.getQr();
			    this.qr=qr;
				this.poster = res[0].image;
			
				let Draw = new draw(this)
				Draw.drawImage(res=>{
					uni.hideLoading()
								 this.image=res;
				})
				
			},
			
			getPost(){
				uni.showLoading({
					title:"正在努力绘制中...",
				})
				return new Promise((resolve,reject)=>{
					this.$u.post('/user/getPoster', {
					}).then(res => {
					    resolve(res)
					}).catch(err => {})
					
				})
		
			},
			jiazai(){
				this.$u.post('/user/index', {
				}).then(res => {
					this.info = res;
				}).catch(err => {})
			},
			go(url){
				uni.navigateTo({
					url:url
				})
			},
			agent(){
				// is_agree_status 是否同意:0=未审核,1=已通过,2=未通过
				if(!this.info.is_agree_status){
					
					uni.navigateTo({
						url:'../agent/index'
					})
					return
					
				}
				if(this.info.is_agree_status==1){
					this.$u.toast("已成为代理")
					return
				}
				if(this.info.is_agree_status==2){
					this.$u.toast("很抱歉,审核未通过")	
					return
				}
			
			},
			
			apply(){
				// is_auth 
				// 0=未申请,1=已申请,2=已通过,3=未通过
				if(!this.info.is_auth){
					uni.navigateTo({
						url:'/pages/apply/index'
					})
					return
				}
				if(this.info.is_auth==1){
				    this.$u.toast("已申请,请耐心等待审核")	
					return
				}
				
				if(this.info.is_auth==2){
				    uni.navigateTo({
				    	url:"/pages/center/index"
				    })
					return
				}
				
				if(this.info.is_auth==3){
				    this.$u.toast("很抱歉,审核未通过")	
					return
				}
			}
			
		}
	}
</script>

<style>
	.page {
		background: #F1F1F1;
		min-height: 100vh;
		display: inline-block;
		width: 750rpx;
	}

	.top {
		width: 750rpx;
		height: 300rpx;
		background: #00C08D;
		border-bottom-left-radius: 25%;
		border-bottom-right-radius: 25%;

		position: relative;
		overflow: hidden;
	}

	.info {
		padding: 40rpx 80rpx;
	}

	.nav {

		position: absolute;
		bottom: 0rpx;
		padding: 20rpx 20rpx;
		width: 600rpx;
		left: 50%;
		transform: translate(-50%);
		background: linear-gradient(90deg, #7B7475 2%, #252024 100%);
		border-radius: 20rpx;
		color: #FFE87F;
		font-size: 24rpx;
		display: flex;
		justify-content: space-between;

	}

</style>
